#include "StdAfx.h"
#include "TelnetShell.h"

CTelnetShell::CTelnetShell(void)
{
}

CTelnetShell::~CTelnetShell(void)
{
}

const char* CTelnetShell::GetTerminalType()
{
	return "vt102";
}

void CTelnetShell::GetWindowSize(int &width, int &height)
{
	width = 80;
	height = 25;
}

void CTelnetShell::Write(unsigned char* dataBuffer, int dataCount)
{
	Send(dataBuffer, dataCount);
}

void CTelnetShell::OnReceive(int nErrorCode)
{
	unsigned char receiveBuffer[4096];
	int receiveCount;
	receiveCount = Receive(receiveBuffer, 4096); 

	switch (receiveCount)
	{
	case 0:
	case SOCKET_ERROR:
		this->connected = false;
		Disconnect();
		break;
	default:
		Negotiate(receiveBuffer, receiveCount);

		if (this->payloadCount > 0)
		{
			OnDataAvailableEvent(this->payloadBuffer, this->payloadCount);
		}
		break;
	}
}

void CTelnetShell::OnClose(int nErrorCode)
{
	this->connected = false;
	OnDisconnectEvent();
}